﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RoughHtml.w3c
{
    public class CSSException : Exception
    {
        /**
    * this error is unspecified.
    */
        public static short SAC_UNSPECIFIED_ERR = 0;

        /**
         * If the operation is not supported
         */
        public static short SAC_NOT_SUPPORTED_ERR = 1;

        /**
         * If an invalid or illegal string is specified
         */
        public static short SAC_SYNTAX_ERR = 2;

        protected short code;

        /**
         * Creates a new CSSException
         */
        public CSSException()
        {
        }

        /**
         * Creates a new CSSException
         */
        public CSSException(String s)
            : base(s)
        {

            this.code = SAC_UNSPECIFIED_ERR;
        }

        /**
         * Creates a new CSSException with an embeded exception.
         * @param a the embeded exception.
         */
        public CSSException(Exception e)
            : base(e.ToString(), e)
        {
            this.code = SAC_UNSPECIFIED_ERR;
        }

        /**
         * Creates a new CSSException with a specific code.
         * @param a the embeded exception.
         */
        public CSSException(short code)
        {
            this.code = code;
        }

        /**
         * Creates a new CSSException with an embeded exception and a specified
         * message.
         * @param code the specified code.
         * @param e the embeded exception.  
         */
        public CSSException(short code, String s, Exception e)
            : base(s, e)
        {
            this.code = code;
        }

        /**
         * Returns the detail message of this throwable object. 
         *
         * @return the detail message of this Throwable, or null if this Throwable
         *         does not have a detail message.  
         */
        public override String Message
        {
            get
            {
                return base.Message;
            }
        }

        /**
         * returns the error code for this exception.
         */
        public short getCode()
        {
            return code;
        }
        /// <summary>
        ///  Returns the internal exception if any, null otherwise.
        /// </summary>
        /// <returns></returns>
        public override Exception GetBaseException()
        {
            var cause = this.GetBaseException();
            return cause is Exception ? (Exception)cause : null;
        }

    }
}
